#ifndef QSHELL_PRIVATE_IMPL_H
#define QSHELL_PRIVATE_IMPL_H

#include <QObject>
#include <QThread>
#include <iostream>

#ifdef Q_OS_WIN
#include <QWinEventNotifier>
#include <windows.h>
#else
#include <QSocketNotifier>
#endif

#include "qcmdparser.h"
#include <QScopedPointer>
#include <QSharedPointer>

class AbstractQConsoleListener : public QObject {
  Q_OBJECT

public:
  AbstractQConsoleListener();
  virtual ~AbstractQConsoleListener();

Q_SIGNALS:
  // finishedGetLine if for internal use
  void finishedGetLine(const QString &strNewLine);

protected:
  virtual void parse_newline(const QString &str) = 0;

private:
#ifdef Q_OS_WIN
  QWinEventNotifier *m_notifier;
#else
  QSocketNotifier *m_notifier;
#endif

private Q_SLOTS:
  void on_finishedGetLine(const QString &strNewLine);

private:
  QThread m_thread;
};

class QShell;
class QShellPrivate : public AbstractQConsoleListener {
  Q_OBJECT
public:
  explicit QShellPrivate(const QString &name, QShell *sh);
  ~QShellPrivate();
  QCmdParser &addSubCommand(const QString &cmd);
  void parse(int argc, char *argv[]);

protected:
  void parse_newline(const QString &str) override;

private:
  QShell *sh;
  QHash<QString, QSharedPointer<QCmdParser>> mSubCmds;
};

#endif
